#include "Operand.hpp"
#include "IdentTable.hpp"

#include <iostream>

Operand::Operand(Value  * value) {
  this->value = value;
  this->ident = -1;
}

Operand::Operand(int ident) {
  this->value = NULL;
  this->ident = ident;
}

Operand::~Operand() {
	if (this->hasValue()) {
		delete this->value;
	} else {
		this->ident = -1;
	}
}

bool Operand::hasValue() {
	return value != NULL;
}

bool Operand::hasIdent() {
	return ! hasValue();
}


void Operand::show(IdentTable * identTable) {
	if (this->hasValue()) {
		value->show();
	} else {
		std::cout << identTable->getName(ident);
	}
}
